package linwen.wang.plugin;

import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
import linwen.wang.DynamicDataSource;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;

import java.sql.SQLException;


/**
 * @author zero
 */
public class DynamicDataSourcePlugin implements InnerInterceptor {
    @Override
    public boolean willDoQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
        DynamicDataSource.name.set("R");
        return true;
    }

    @Override
    public boolean willDoUpdate(Executor executor, MappedStatement ms, Object parameter) throws SQLException {
        DynamicDataSource.name.set("W");
        return true;
    }


}